package org.sensation;

import java.io.IOException;
import org.sensation.file.channel.FileReadChannel;
import org.sensation.server.operation.request.Command;
import org.sensation.server.send.CommanderWithServerContact;

public class CommandSenderForFileTransfer {
	private CommanderWithServerContact commander;
	private FileReadChannel readChannel;
	private Command command;
	private int blockSize = 10;
	
	public CommandSenderForFileTransfer(CommanderWithServerContact commander) {
		this.commander = commander;
		this.command = command;
	}

	public void sendFile(String filePath) throws Exception{
		setupCommand(filePath);
		
		Command serverOperation = commander.setup();
		
		commander.sendingFile(readChannel);
	
//		Command completeCommand = commander.requestFileTransferComplete();
			
	}

	private void setupCommand(String filePath) throws IOException {
		setupFileReadChannel(filePath);
		readChannel.size();
		command = new Command();
		command.setFileName(readChannel.getFileName());
		command.setFileSize(readChannel.size());
		command.setBlockNumber(1);
	}

	private void setupFileReadChannel(String filePath) throws IOException {
		readChannel = new FileReadChannel(filePath, blockSize);
	}
}
